package com.teach.web;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teach.Const;
import com.teach.dto.ArticleSearch;
import com.teach.entity.Article;
import com.teach.service.ArticleService;
import com.teach.service.ArticleTypeService;

import cn.hutool.core.util.StrUtil;

/**
 * <pre>
 * TODO : 文 章相关控制器
 * ClassName : com.teach.web.ArticleController
 * Author : J.L.Zhou
 * Date : 2020-11-08 16:25
 * Version : V1.0
 * Copyright 2020 jlzhou.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes</pre>
 */
@Controller
@RequestMapping("/article")
public class ArticleController {

	@Autowired
	private ArticleService articleService;
	@Autowired
	private ArticleTypeService articleTypeService;
	
	@GetMapping("page"+Const.WEB_EXT)
	public String page(ArticleSearch search,Page<Article> page,String template,Model model) {
		model.addAttribute("p", articleService.page(search, page));
		model.addAttribute("type", articleTypeService.getById(search.getArticleTypeId()));
		if(StrUtil.hasBlank(template)) {
			return "/article/page";
		}else {
			return "/article/page-"+template;
		}
	}
}
